////////////////////////////////////////////////////////////////////////////////
//
//  Title     : imaqIO.h
//  Platforms : All
//  Copyright : National Instruments 2005.  All Rights Reserved.
//  Access    : Public
//  Purpose   : Outlines the IMAQ IO Interface.
//
////////////////////////////////////////////////////////////////////////////////
//============================================================================
//  Preamble
//============================================================================
#if !defined(imaqIO_h)
#define imaqIO_h

#ifdef _CVI_
#pragma  EnableLibraryRuntimeChecking
#endif


//============================================================================
//  Align Packing to match implementation
//============================================================================
#pragma pack(push)
#pragma pack(1)


//============================================================================
//  Defines
//============================================================================
#if (defined(__cplusplus) || defined(__cplusplus__))
    #define USER_EXTERN_C extern "C"
#else
    #define USER_EXTERN_C
#endif

#if !(defined(USER_FUNC))
    #if defined(EXPORT)
        #define USER_FUNC USER_EXTERN_C __declspec(dllexport) long __stdcall
    #else
        #define USER_FUNC USER_EXTERN_C __declspec(dllimport) long __stdcall
    #endif
#endif

#if defined(_MSC_VER) && !defined(_CVI_) && !defined(__BORLANDC__)
    #pragma comment(lib, "delayimp.lib")  
    #pragma comment(lib, "imaqio.lib")
    #pragma comment(linker, "/DelayLoad:imaqio.dll")
#endif

//==============================================================================
//  Typedefs
//==============================================================================
#if (defined(__cplusplus) || defined(__cplusplus__))
struct IMAQIO_SESSION_struct;
typedef IMAQIO_SESSION_struct* IMAQIO_SESSION; 
struct IMAQIO_PULSE_ID_struct;
typedef IMAQIO_PULSE_ID_struct* IMAQIO_PULSE_ID; 
#else
typedef struct IMAQIO_SESSION_struct {long param;} IMAQIO_SESSION;
typedef struct IMAQIO_PULSE_ID_struct {long param;} IMAQIO_PULSE_ID;
#endif
typedef signed long IMAQIO_ERR;


//==============================================================================
//  Error Codes
//==============================================================================
#define IMAQIO_ERR_NO_ERROR                                                          0       // No Error
#define IMAQIO_ERR_DEVICE_NOT_FOUND                                                  -301500 // Device Not Found
#define IMAQIO_ERR_DEVICE_IN_USE                                                     -301501 // Device in Use
#define IMAQIO_ERR_INVALID_POINTER                                                   -301502 // Invalid Pointer
#define IMAQIO_ERR_OUT_OF_MEMORY                                                     -301503 // Out of Memory
#define IMAQIO_ERR_ERROR_TEXT_TOO_SHORT                                              -301504 // Error Text too short
#define IMAQIO_ERR_ERROR_NOT_FOUND                                                   -301505 // Error not Found
#define IMAQIO_ERR_INTERNAL_ERROR                                                    -301506 // Internal Error
#define IMAQIO_ERR_INVALID_SESSION                                                   -301507 // Invalid Session
#define IMAQIO_ERR_INVALID_SIGNAL_FOR_THIS_OPERATION                                 -301509 // Invalid signal for this operation
#define IMAQIO_ERR_INVALID_SIGNAL_STATE_FOR_THIS_CHANNEL                             -301510 // Invalid Signal State for this channel
#define IMAQIO_ERR_INVALID_PULSE_OUTPUT_SIGNAL                                       -301511 // Invalid pulse output signal
#define IMAQIO_ERR_INVALID_PULSE_TRIGGER_SIGNAL                                      -301512 // Invalid pulse trigger signal
#define IMAQIO_ERR_PULSE_OUTPUT_ALREADY_IN_USE                                       -301513 // Pulse output already in use
#define IMAQIO_ERR_INVALID_POLARITY                                                  -301514 // Invalid Polarity
#define IMAQIO_ERR_INVALID_TIMEBASE                                                  -301515 // Invalid timebase
#define IMAQIO_ERR_INVALID_PULSE_ID                                                  -301516 // Invalid Pulse ID
#define IMAQIO_ERR_INVALID_ATTRIBUTE_TO_READ                                         -301517 // Invalid Attribute to Read
#define IMAQIO_ERR_INVALID_WATCHDOG_TIMER_EXPIRATION_ACTION                          -301518 // Invalid Watchdog timer expiration action
#define IMAQIO_ERR_TIMEOUT_OUT_OF_RANGE                                              -301519 // This Watchdog timer can only handle 16 bit values
#define IMAQIO_ERR_ATTRIBUTE_NOT_SETTABLE                                            -301520 // Attribute Not Settable
#define IMAQIO_ERR_INVALID_PULSE_MODE                                                -301521 // Invalid Pulse Mode
						 

//============================================================================
//  Enumerations
//============================================================================
//----------------------------------------------------------------------------
//  Signal States
//----------------------------------------------------------------------------
typedef enum  IMAQIOSignalStateEnum {
    IMAQIO_SIGNAL_STATE_RISING,
    IMAQIO_SIGNAL_STATE_FALLING,
    IMAQIO_SIGNAL_STATE_HIGH,
    IMAQIO_SIGNAL_STATE_LOW,
    IMAQIO_SIGNAL_STATE_HI_Z,
    IMAQIO_SIGNAL_STATE_INVALID = 0xFFFFFFFF
} IMAQIOSignalState;


//----------------------------------------------------------------------------
//  General Purpose I/O IMAQIOSignalTypes
//----------------------------------------------------------------------------
typedef enum IMAQIOSignalTypeEnum {
    IMAQIO_SIGNAL_EXTERNAL = 0,
    IMAQIO_SIGNAL_RTSI     = 1,
    IMAQIO_SIGNAL_ISO_IN   = 2,
    IMAQIO_SIGNAL_ISO_OUT  = 3,
    IMAQIO_SIGNAL_STATUS   = 4,
    IMAQIO_SIGNAL_TTL_IN   = 5,
    IMAQIO_SIGNAL_TTL_OUT  = 6,
    IMAQIO_SIGNAL_INVALID  = 0xFFFFFFFF
} IMAQIOSignalType;


//----------------------------------------------------------------------------
//  General Purpose I/O IMAQIOSignalTypes
//----------------------------------------------------------------------------
typedef enum IMAQIOStatusSignalEnum {
    IMAQIO_STATUS_SIGNAL_NONE,
    IMAQIO_STATIS_SIGNAL_INVALID = 0xFFFFFFFF
} IMAQIOStatusSignal;

//----------------------------------------------------------------------------
//  Polarity
//----------------------------------------------------------------------------
typedef enum IMAQIOPolarityEnum {
    IMAQIO_POLARITY_HIGH_TRUE,
    IMAQIO_POLARITY_LOW_TRUE,
    IMAQIO_POLARITY_INVALID = 0xFFFFFFFF
} IMAQIOPolarity;

//----------------------------------------------------------------------------
//  Expiration Actions
//----------------------------------------------------------------------------
typedef enum IMAQIOExpirationActionEnum {
    IMAQIO_EXPIRATION_ACTION_INDICATOR_ONLY,
    IMAQIO_EXPIRATION_ACTION_ASSERT_TTL_OUT_0,
    IMAQIO_EXPIRATION_ACTION_SHUTDOWN,
    IMAQIO_EXPIRATION_ACTION_INVALID = 0xFFFFFFFF
} IMAQIOExpirationAction;


//----------------------------------------------------------------------------
//  Delay Units
//----------------------------------------------------------------------------
typedef enum IMAQIOTimebaseEnum {
    IMAQIO_TIMEBASE_ENCODER_TICKS = 4,
    IMAQIO_TIMEBASE_MICROSECONDS = 5,
    IMAQIO_TIMEBASE_INVALID = 0xFFFFFFFF
} IMAQIOTimebase;


//----------------------------------------------------------------------------
//  Attributes
//----------------------------------------------------------------------------
typedef enum IMAQIOAttributeEnum {
    IMAQIO_ATTRIBUTE_PRODUCT_SELECT_CURRENT,
    IMAQIO_ATTRIBUTE_PRODUCT_SELECT_LATCHED,
    IMAQIO_ATTRIBUTE_QUADRATURE_ENCODER,
    IMAQIO_ATTRIBUTE_WATCHDOG_STATUS,
    IMAQIO_ATTRIBUTE_ISOPOWER_PRESENT,
    IMAQIO_ATTRIBUTE_INVALID = 0xFFFFFFFF
} IMAQIOAttribute;


//----------------------------------------------------------------------------
//  Pulse Modes
//----------------------------------------------------------------------------
typedef enum IMAQIOPulseModeEnum {
    IMAQIO_PULSE_MODE_TRAIN = 1,
    IMAQIO_PULSE_MODE_SINGLE = 2,
    IMAQIO_PULSE_MODE_SINGLE_REARM = 3,
    IMAQIO_PULSE_MODE_INVALID = 0xFFFFFFFF
} IMAQIOPulseMode;


//----------------------------------------------------------------------------
//  Change Detect Edges
//----------------------------------------------------------------------------
typedef enum IMAQIOChangeDetectModeEnum {
    IMAQIO_CHANGE_DETECT_ANY_EDGE = 0,
    IMAQIO_CHANGE_DETECT_RISING_EDGE = 1,
    IMAQIO_CHANGE_DETECT_FALLING_EDGE = 2
} IMAQIOChangeDetectMode;


//============================================================================
//  Functions
//============================================================================
USER_FUNC imaqIOOpen(const char* deviceName, IMAQIO_SESSION* id);
USER_FUNC imaqIOClose(IMAQIO_SESSION id);
USER_FUNC imaqIORead(IMAQIO_SESSION id, IMAQIOSignalType signalType, unsigned long signalNumber, IMAQIOSignalState* value);
USER_FUNC imaqIODrive(IMAQIO_SESSION id, IMAQIOSignalType signalType, unsigned long signalNumber, IMAQIOSignalState value);
USER_FUNC imaqIOPulseCreate(IMAQIO_SESSION id, 
	IMAQIOTimebase DelayTimebase, unsigned long Delay, 
	IMAQIOTimebase WidthTimebase, unsigned long Width, 
	IMAQIOSignalType triggerSignalType, unsigned long triggerSignalNumber, IMAQIOPolarity triggerSignalPolarity, 
	IMAQIOSignalType outputSignalType, unsigned long outputSignalNumber, IMAQIOPolarity outputSignalPolarity, 
	IMAQIOPulseMode pulseMode, IMAQIO_PULSE_ID *PulseID);
USER_FUNC imaqIOPulseStart(IMAQIO_SESSION id, IMAQIO_PULSE_ID PulseID);
USER_FUNC imaqIOPulseStop(IMAQIO_SESSION id, IMAQIO_PULSE_ID PulseID);
USER_FUNC imaqIOPulseDispose(IMAQIO_SESSION id, IMAQIO_PULSE_ID PulseID);
USER_FUNC imaqIOWatchdogConfigure(IMAQIO_SESSION id, unsigned long timeout, IMAQIOExpirationAction expirationAction);
USER_FUNC imaqIOWatchdogArm(IMAQIO_SESSION id);
USER_FUNC imaqIOWatchdogClear(IMAQIO_SESSION id);
USER_FUNC imaqIOWatchdogWhack(IMAQIO_SESSION id);
USER_FUNC imaqIOGetAttribute(IMAQIO_SESSION id, 
	IMAQIOAttribute attribute, unsigned long *value);
USER_FUNC imaqIOSetAttribute(IMAQIO_SESSION id, 
	IMAQIOAttribute attribute, unsigned long value);
USER_FUNC imaqIOSetShutdownState(IMAQIO_SESSION id, 
	IMAQIOSignalType signalType, unsigned long signalNumber, 
	IMAQIOSignalState value);
USER_FUNC imaqIOGetShutdownState(IMAQIO_SESSION id, 
	IMAQIOSignalType signalType, unsigned long signalNumber, 
	IMAQIOSignalState *value);
USER_FUNC imaqIOEnableShutdown(IMAQIO_SESSION id, 
	unsigned long enableShutdown);
USER_FUNC imaqIOQueryShutdown(IMAQIO_SESSION id, 
	unsigned long *shutdownEnabled);
USER_FUNC imaqIOChangeDetectConfigure(IMAQIO_SESSION id, IMAQIOSignalType triggerType, unsigned long triggerNumber, IMAQIOChangeDetectMode detectMode, unsigned long filter);
USER_FUNC imaqIOChangeDetectQuery(IMAQIO_SESSION id, IMAQIOSignalType triggerType, unsigned long triggerNumber, unsigned long* changed);
USER_FUNC imaqIOChangeDetectReset(IMAQIO_SESSION id, IMAQIOSignalType triggerType, unsigned long triggerNumber);
USER_FUNC imaqIOGetErrorText(IMAQIO_ERR errorCode, 
     unsigned long *errorTextLength, char *errorText);


//============================================================================
//  Revert packaging alignment
//============================================================================
#pragma pack(pop)


//============================================================================
//  The end(if)
//============================================================================
#endif
